package com.nbsaas.boot.article.rest.convert;

import com.nbsaas.boot.article.data.entity.Article;
import com.nbsaas.boot.article.api.domain.request.ArticleRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.article.data.entity.ArticleCatalog;
            import com.nbsaas.boot.article.data.entity.ArticleDocument;
            import com.nbsaas.boot.jpa.data.entity.User;

/**
* 请求对象转换成实体对象
*/

public class ArticleEntityConvert  implements Converter<Article, ArticleRequest> {

    @Override
    public Article convert(ArticleRequest source) {
        Article result = new Article();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getCatalog()!=null){
                    ArticleCatalog catalog =new ArticleCatalog();
                    catalog.setId(source.getCatalog());
                    result.setCatalog(catalog);
                    }
                    if(source.getDocument()!=null){
                    ArticleDocument document =new ArticleDocument();
                    document.setId(source.getDocument());
                    result.setDocument(document);
                    }
                    if(source.getUser()!=null){
                    User user =new User();
                    user.setId(source.getUser());
                    result.setUser(user);
                    }
        return result;
    }
}

